<?php
/**
 * 钉钉免登回调接收授权码
 */
namespace Buu\Modules\DingCallback\Apis;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class Notify extends Controller
{
    public function index(Request $request)
    {
        $requestData = $request->all();
        $code = $requestData['code'];
        $state = $requestData['state'];
        if(empty($code) || empty($state)){
            echo "缺少参数";
            exit();
        }
        $stateArr = explode("!",$state);
        $domain = $stateArr[0] ? $stateArr[0] : "https://beerus.haohaozhu.me";
        $url = $stateArr[1] ? $stateArr[1] : "admin";
        $loginUrl = $domain."/admin/auth/dinglogin?code=$code&url=$url";
        header('Location:'.$loginUrl);
    }
}
